#!/usr/bin/env python
# -*- coding: utf-8 -*-

''' Autor: Neuza Figueira '''

from BeautifulSoup import BeautifulSoup
import urllib2
    
''' Class to count the HTML tags '''
class TagCounter:
    @staticmethod
    def counter(url):
        theList = []
        theName = urllib2.urlopen(str(url)) 
        theSoup = BeautifulSoup(theName)
        
        try:
            total = 0
            for h1 in theSoup.h1:
                total = total + 1 
                pass
            theList.append( "Number of <H1> tags: " + str(total))
        except:
            theList.append( "<H1> tags not found")
            pass

        try:
            total = 0
            for h2 in theSoup.h2:
                total = total + 1
                pass
            theList.append( "Number of <H2> tags: " + str(total))
        except:
            theList.append( "<H2> tags not found")
            pass

        try:
            total = 0
            for h3 in theSoup.h3:
                total = total + 1
                pass
            theList.append( "Number of <H3> tags: " + str(total))
        except:
            theList.append( "<H3> tags not found")
            pass

        try:
            total = 0
            for div in theSoup.div:
                total = total + 1
                pass
            theList.append( "Number of <DIV> tags: " + str(total))
        except:
            theList.append( "<DIV> tags not found")
            pass

        try:
            total = 0
            for p in theSoup.p:
                total = total + 1
                pass
            theList.append( "Number of <P> tags: " + str(total))
        except:
            theList.append( "<P> tags not found")
            pass

        try:
            total = 0
            for ul in theSoup.ul:
                total = total + 1
                pass
            theList.append( "Number of <UL> tags: " + str(total))
        except:
            theList.append( "<UL> tags not found")
            pass

        try:
            total = 0
            for ol in theSoup.ol:
                total = total + 1
                pass
            theList.append( "Number of <OL> tags: " + str(total))
        except:
            theList.append( "<OL> tags not found")
            pass

        return theList	
